<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" :inline="true" :rules="Rules" label-width="auto"
                 @submit.native.prevent>
            <el-form-item label="分类名称" desc="分类名称" prop="name">
                <el-input v-model.trim="formData.name" placeholder="分类名称" clearable size="small" style="width:120px;" />
            </el-form-item>
            <el-form-item label="所属上级类别" desc="所属上级类别[关系=SysClass]" prop="parentId">
                <el-input v-model.trim="formData.parentName" placeholder="所属上级类别" clearable size="small"
                          style="width:120px;"
                          :disabled="true"
                           />
            </el-form-item>
            <!--   <el-form-item label="所有分类路径" desc="所有分类路径" prop="parentIdPath">
                   <el-input v-model.trim="formData.parentIdPath" placeholder="所有分类路径" clearable size="small"
                             style="width:120px;" />
               </el-form-item>-->
              <el-form-item label="拓展类型" desc="拓展类型" prop="expendType">
                  <dic-select v-model="formData.expendType" :code="dicInner.sys_class_expendType" placeholder="拓展类型"
                              clearable size="small" style="width:120px;" />
              </el-form-item>
            <!--  <el-form-item label="类别深度" desc="类别深度" prop="deep">
                  <el-input v-model.trim="formData.deep" placeholder="类别深度" clearable size="small" style="width:120px;" />
              </el-form-item>-->
            <!--    <el-form-item label="分类类型名称" desc="分类类型名称" prop="typeInfo">
                    <dic-select v-model="formData.typeInfo" :code="dicInner.sys_class_typeInfo" placeholder="分类类型名称"
                                clearable size="small" style="width:120px;" />
                </el-form-item>-->
            <!--   <el-form-item label="分类图片[查询]" desc="分类图片[查询]" prop="img">
                   <el-input v-model.trim="formData.img" placeholder="分类图片[查询]" clearable size="small"
                             style="width:120px;" />
               </el-form-item>-->
            <el-form-item label="排序号" desc="排序号" prop="orderNum">
                <el-input-number v-model.trim="formData.orderNum" placeholder="排序号" clearable size="small"
                                 style="width:120px;" />
            </el-form-item>
            <!--      <el-form-item label="信息级别" desc="信息级别 0系统级 10租户级" prop="infoLevel">
                      <el-input v-model.trim="formData.infoLevel" placeholder="信息级别 0系统级 10租户级" clearable size="small"
                                style="width:120px;" />
                  </el-form-item>-->
        </el-form>
    </div>
</template>
<script>  import { getUrlParam } from '@/utils/index';
import { alertWithPaylod } from '@/utils/alertUtil';
import * as  api from '@/apis/sysClass.api.js';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import { fillData, validatePromise } from '@/utils/index';

const Rules = {
  'id': [{ required: false, message: '主键ID', trigger: 'blur' }],
  'name': [{ required: false, message: '分类名称', trigger: 'blur' }],
  'parentId': [{ required: false, message: '所属上级类别[关系=SysClass]', trigger: 'blur' }],
  'parentIdPath': [{ required: false, message: '所有分类路径', trigger: 'blur' }],
  'expendType': [{ required: false, message: '拓展类型', trigger: 'blur' }],
  'deep': [{ required: false, message: '类别深度', trigger: 'blur' }],
  'typeInfo': [{ required: false, message: '分类类型名称', trigger: 'blur' }],
  'img': [{ required: false, message: '分类图片[查询]', trigger: 'blur' }],
  'orderNum': [{ required: false, message: '排序号', trigger: 'blur' }],
  'remarks': [{ required: false, message: '备注', trigger: 'blur' }],
  'infoLevel': [{ required: false, message: '信息级别', trigger: 'blur' }],
  'tenantType': [{ required: false, message: '租户类型', trigger: 'blur' }],
  'tenantId': [{ required: false, message: '租户ID', trigger: 'blur' }],
  'delState': [{ required: false, message: '有效状态[数据字典=del_state]', trigger: 'blur' }],
  'addUser': [{ required: false, message: '添加人', trigger: 'blur' }],
  'addUserId': [{ required: false, message: '添加人ID', trigger: 'blur' }],
  'addTime': [{ required: false, message: '添加时间', trigger: 'blur' }],
  'editUser': [{ required: false, message: '最近更新人', trigger: 'blur' }],
  'editUserId': [{ required: false, message: '最近更新人ID', trigger: 'blur' }],
  'lastEditTime': [{ required: false, message: '最近更新时间', trigger: 'blur' }],
  'serverNumber': [{ required: false, message: '服务器编号ID', trigger: 'blur' }],
};
const dicInner = {
  '___sys_class_id': '主键ID',
  'sys_class_id': 'sys_class_id',
  '___sys_class_name': '分类名称',
  'sys_class_name': 'sys_class_name',
  '___sys_class_parentId': '所属上级类别[关系=SysClass]',
  'sys_class_parentId': 'sys_class_parentId',
  '___sys_class_parentIdPath': '所有分类路径',
  'sys_class_parentIdPath': 'sys_class_parentIdPath',
  '___sys_class_expendType': '拓展类型',
  'sys_class_expendType': 'sys_class_typeInfo',
  '___sys_class_deep': '类别深度',
  'sys_class_deep': 'sys_class_deep',
  '___sys_class_typeInfo': '分类类型名称',
  'sys_class_typeInfo': 'sys_class_typeInfo',
  '___sys_class_img': '分类图片[查询]',
  'sys_class_img': 'sys_class_img',
  '___sys_class_orderNum': '排序号',
  'sys_class_orderNum': 'sys_class_orderNum',
  '___sys_class_remarks': '备注',
  'sys_class_remarks': 'sys_class_remarks',
  '___sys_class_infoLevel': '信息级别 0系统级 10租户级',
  'sys_class_infoLevel': 'sys_class_infoLevel',
  '___sys_class_tenantType': '租户类型 1应用管理者2应用消息者',
  'sys_class_tenantType': 'sys_class_tenantType',
  '___sys_class_tenantId': '租户ID',
  'sys_class_tenantId': 'sys_class_tenantId',
  '___sys_class_delState': '有效状态[数据字典=del_state] 1有效  5删除',
  'sys_class_delState': 'sys_class_delState',
  '___sys_class_addUser': '添加人',
  'sys_class_addUser': 'sys_class_addUser',
  '___sys_class_addUserId': '添加人ID',
  'sys_class_addUserId': 'sys_class_addUserId',
  '___sys_class_addTime': '添加时间',
  'sys_class_addTime': 'sys_class_addTime',
  '___sys_class_editUser': '最近更新人',
  'sys_class_editUser': 'sys_class_editUser',
  '___sys_class_editUserId': '最近更新人ID',
  'sys_class_editUserId': 'sys_class_editUserId',
  '___sys_class_lastEditTime': '最近更新时间',
  'sys_class_lastEditTime': 'sys_class_lastEditTime',
  '___sys_class_serverNumber': '服务器编号ID',
  'sys_class_serverNumber': 'sys_class_serverNumber',
};
export default {
  name: 'sysClassModify',
  data() {
    return {
      api: api,
      Rules,
      dicInner,
      formData: {
        'id': '',
        'name': '',
        'parentId': '',
        'parentIdPath': '',
        'expendType': '',
        'deep': '',
        'typeInfo': '',
        'img': '',
        'orderNum': '',
        'remarks': '',
        'infoLevel': '',
        'tenantType': '',
        'tenantId': '',
        'delState': '',
        'addUser': '',
        'addUserId': '',
        'addTime': '',
        'editUser': '',
        'editUserId': '',
        'lastEditTime': '',
        'serverNumber': '',
        parentName: '',
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
  },
  computed: {},
  watch: {},
  methods: {
    /**       *  @params _data.         * @desc 初始化        */
    initByDialog(_data) {
      fillData(this.formData, _data);
      console.log('初始化数据', this.formData);
      // region 设置 默认
      if (!this.formData.parentId) {
        this.formData.parentName = '顶级父类';
      }
      
      // endregion
    }, async submitByDialog(_data) {
      var isyes = await validatePromise.call(this, 'queryForm');
      if (!isyes) {
        return { success: false, message: '请检查必填项' };
      }
      var func = this.formData.id ? api.update : api.add;
      var result = await func(this.formData);
      alertWithPaylod(result);
      return result;
    },
  },
};</script>
